import java.util.*;

/**
 * Created by qtbui on 2017/9/21.
 */
class Solution
{
    public int maxSubArray(int[] nums)
    {
        int maxNum=nums[0];
        int sum=0;

        for(int i=0;i<nums.length;++i)
        {
            if(sum>0)
            {
                sum+=nums[i];
            }
            else
            {
                sum=nums[i];
            }
            if(sum>maxNum)
            {
                maxNum=sum;
            }
        }

        return maxNum;
    }
}

public class test
{
    public static void main(String[] args)
    {
        int[] nums=new int[]{-2,-1};
        int r = new Solution().maxSubArray(nums);
        System.out.println(r);
    }
}
